
Vue.component2("a_1_0_2_28_1_dialog",{
  template:`
  <div>

  <el-dialog title="添加字段" :visible.sync="dialogVisible" width="50%">
  <el-form :model="form">
    <el-form-item label="字段英文名称*">
      <el-input v-model="form.en_name"></el-input>
    </el-form-item>
    <el-form-item label="字段中文名称">
      <el-input v-model="form.ch_name"></el-input>
    </el-form-item>
    <el-form-item label="字段类型*">
      <el-select v-model="form.field_type" placeholder="请选择字段类型">
        <el-option label="TEXT【字符串】" value="TEXT"></el-option>
        <el-option label="INTEGER【整数】" value="INTEGER"></el-option>
        <el-option label="BOOLEAN【布尔】" value="BOOLEAN"></el-option>
        <el-option label="DATETIME【日期】" value="DATETIME"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="字段默认值*" v-if="form.field_type === 'INTEGER' " >
        <div class="input-container">

      <div @click="form.default_value--"style="
    width: 20px;
    font-size: 55px;">-</div>

      <input

        type="text"
        v-model.number="form.default_value"
        @input="validateInput"
        class="el-input__inner"

        placeholder="输入数值"

      />

      <div  @click="form.default_value++" style="
    width: 20px;
    font-size: 55px;">+</div>

    </div>
    </el-form-item>
    <el-form-item label="字段默认值*" v-if="form.field_type === 'TEXT' " >
      <div class="el-select">
      <input
        type="text"
        class="el-input__inner"
        v-model.number="form.default_value"
        placeholder="输入数值"
      /></div>
    </el-form-item>
    
    <el-form-item label="字段默认值*" v-if="form.field_type === 'DATETIME' ">
      <el-select v-model="form.default_value" placeholder="请选择字段类型">
        <el-option label="create_time【创建时间】" value="create_time"></el-option>
        <el-option label="update_time【更新时间】" value="update_time"></el-option>
      </el-select>
    </el-form-item>

    <el-form-item label="字段默认值*" v-if="form.field_type === 'BOOLEAN' ">
      <el-select v-model="form.default_value" placeholder="请选择字段类型">
        <el-option label="True【是】" value="true"></el-option>
        <el-option label="False【否】" value="false"></el-option>
      </el-select>
    </el-form-item>
      
    <el-form-item label="索引类型*">
      <el-select v-model="form.index_type" placeholder="请选择索引类型">
        <el-option label="None【无】" value="None"></el-option>
        <el-option label="PRIMARY KEY【主键】" value="PRIMARY KEY"></el-option>
        <el-option label="Unique Index【唯一索引】" value="Unique Index"></el-option>
        <el-option label="Index【索引】" value="Index"></el-option>
      </el-select>
    </el-form-item>





    <el-form-item label="字段解释">
      <el-input v-model="form.note"></el-input>
    </el-form-item>
    <div class="el-form-item">
<div  style="
font-size: 14px;
color: #606266;
line-height: 40px;
padding: 0 12px 0 0;
">额外参数</div>
      <div class="el-form-item__content">
        <div v-for="(value,key) in form.ps" :key="key" class="extra-param-tree">
<div class="key-value-pair">
          <input 
        type="text"
        class="el-input__inner"v-model="value.k" placeholder="key"></input>
          <input 
        type="text"
        class="el-input__inner"v-model="value.v" placeholder="Value" style="margin-left: 20px;"></input>
<button type="button" class="el-button delete-btn el-button--danger" @click="removeExtraParam(key)"><span>删除</span></button>
        </div>
      </div>
      </div>
<button type="button" class="el-button el-button--primary" @click="addExtraParam"><!----><!----><span>添加参数</span></button>
    </div>
  </el-form>
  <div slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取消</el-button>
    <el-button type="primary" @click="submitForm">确定</el-button>
  </div>
</el-dialog>
  </div>
  `,
  data(){
    return {
      
      dialogVisible: false,
      form: {
        index:1,
        en_name: '',//字段英文名称
        field_type: '',//字段类型
        default_value: '',//字段默认值
        ch_name: '',//字段中文名称
        index_type:'None',//索引类型 默认无
        note: '',//字段解释
        ps:{//字段 自定义参数
"1":{"k":"params1","v":"value1"}
}
    }
  }
},
watch:{
"form.field_type":function(e){
  // <el-option label="TEXT【字符串】" value="TEXT"></el-option>
  // <el-option label="INTEGER【整数】" value="INTEGER"></el-option>
  // <el-option label="BOOLEAN【布尔】" value="BOOLEAN"></el-option>
  // <el-option label="DATETIME【日期】" value="DATETIME"></el-option>
if(e=='INTEGER'){
  this.form.default_value=0;
}else if(e=='TEXT'){
  this.form.default_value='';
}else if(e=='BOOLEAN'){
  this.form.default_value='true';
}else if(e=='DATETIME'){
  this.form.default_value='create_time';
}
}
},
methods:{
  初始化:function(data){
      if(data){
          this.form.en_name=data.en_name;
          this.form.field_type=data.field_type;
          this.form.default_value=data.default_value;
          this.form.ch_name=data.ch_name;
          this.form.note=data.note;
          this.form.index_type=data.index_type;
          this.form.index=data.index;
          this.$set(this.form,'ps',JSON.parse(JSON.stringify(data.ps)));
      }else{
          
  this.form.en_name='';
  this.form.field_type='INTEGER';
  this.form.default_value=0;
  this.form.ch_name='';
  this.form.note='';
  this.form.index_type='None';
  this.form.index=1;
  this.$set(this.form,'ps',{
    "1":{"k":"params1","v":"value1"}
});
      }
    
  },
  validateInput(event) {
    // 获取输入框的值
    let value = event.target.value;
    
    // 去除非数值字符，如果为空则置为0
    value = value.replace(/\D/g, '');
    value = value === '' ? 0 : parseInt(value, 10);
    
    // 由于 v-model.number 会自动将输入转换为数字，我们在这里也直接设置数字
    this.form.default_value = isNaN(value) ? 0 : value;
  },
  increment() {
    this.form.default_value++;
  },
  decrement() {
    if (this.form.default_value > 0) {
      this.form.default_value--;
    }
  },
  addExtraParam() {
    this.form.index++;
    this.form.ps[this.form.index+'']={'k':'params'+this.form.index,'v':'value'+this.form.index};
    
    this.$set(this.form,'ps',JSON.parse(JSON.stringify(this.form.ps)));
  },
  removeExtraParam(index) {
    delete this.form.ps[index];
    this.$set(this.form,'ps',JSON.parse(JSON.stringify(this.form.ps)));
  },
  submitForm() {
    console.log(this.form);
    try{
      this.callback(this.form);
    }catch{}
    // 在这里实现提交到 SQLite3 数据库的逻辑
    this.dialogVisible = false;
  },
}


}

)
a_1_0_2_28_1_open_dialog=function(obj){
  let data=obj.data;
  let callback=obj.callback;
  if(!window.a_1_0_2_28_1_open_dialog_dom){

      new_dom = document.createElement('a_1_0_2_28_1_dialog');  
      new_dom.id = 'a_1_0_2_28_1_dialog'; // 为div设置一个唯一的ID 
      document.body.appendChild(new_dom);
      //设置dom属性 ref值为ref_obj
      new_dom.setAttribute('ref', 'ref_obj');
      let t_deepcopy_data=JSON.parse(JSON.stringify({}));
      new_dom.setAttribute(':deepcopy_data',"deepcopy_data");//初始化vue模板的参数
      let vue_dct={'el':new_dom,data:{true:true,false:false,null:null,deepcopy_data:t_deepcopy_data}}
      let new_vue=new Vue(vue_dct);
      // window.test_vue=new_vue;
      window.a_1_0_2_28_1_open_dialog_dom=new_vue.$el;
      // next_dom2=new_vue.$el;
      window.a_1_0_2_28_1_open_dialog_vue=new_vue.$refs.ref_obj;
  }
  window.a_1_0_2_28_1_open_dialog_vue.dialogVisible=true;
  
  window.a_1_0_2_28_1_open_dialog_vue.初始化(data);
  window.a_1_0_2_28_1_open_dialog_vue.callback=callback;
}

Vue.component2("a_1_0_2_28_1_2_dialog",{
  template:`
  <div>

  <el-dialog title="添加数据库" :visible.sync="dialogVisible" width="50%">
  <el-form :model="form">
    <el-form-item label="数据库 表的英文名称*">
      <el-input v-model="form.en_name"></el-input>
    </el-form-item>
    <el-form-item label="数据库 表的中文名称">
      <el-input v-model="form.ch_name"></el-input>
    </el-form-item>
    <el-form-item label="数据库 表解释">
      <el-input v-model="form.note"></el-input>
    </el-form-item>
    <div class="el-form-item">
<div  style="
font-size: 14px;
color: #606266;
line-height: 40px;
padding: 0 12px 0 0;
">额外参数</div>
      <div class="el-form-item__content">
        <div v-for="(value,key) in form.ps" :key="key" class="extra-param-tree">
<div class="key-value-pair">
          <input 
        type="text"
        class="el-input__inner"v-model="value.k" placeholder="key"></input>
          <input 
        type="text"
        class="el-input__inner"v-model="value.v" placeholder="Value" style="margin-left: 20px;"></input>
<button type="button" class="el-button delete-btn el-button--danger" @click="removeExtraParam(key)"><span>删除</span></button>
        </div>
      </div>
      </div>
<button type="button" class="el-button el-button--primary" @click="addExtraParam"><!----><!----><span>添加参数</span></button>
    </div>
  </el-form>
  <div slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取消</el-button>
    <el-button type="primary" @click="submitForm">确定</el-button>
  </div>
</el-dialog>
  </div>
  `,
  data(){
    return {
      
      dialogVisible: false,
      form: {
        index:1,
        en_name: '',//英文名称
        ch_name: '',//中文名称
        note: '',//解释
        ps:{//自定义参数
"1":{"k":"params1","v":"value1"}
}
    }
  }
},
watch:{
},
methods:{
  初始化:function(data){
    this.form.en_name=data.en_name;
    this.form.ch_name=data.ch_name;
    this.form.index=data.index;
    this.form.note=data.note;
    this.$set(this.form,'ps',JSON.parse(JSON.stringify(data.ps)));
    
  },
  addExtraParam() {
    this.form.index++;
    this.form.ps[this.form.index+'']={'k':'params'+this.form.index,'v':'value'+this.form.index};
    
    this.$set(this.form,'ps',JSON.parse(JSON.stringify(this.form.ps)));
  },
  removeExtraParam(index) {
    delete this.form.ps[index];
    this.$set(this.form,'ps',JSON.parse(JSON.stringify(this.form.ps)));
  },
  submitForm() {
    console.log(this.form);
    try{
      this.callback(this.form);
    }catch{}
    // 在这里实现提交到 SQLite3 数据库的逻辑
    this.dialogVisible = false;
  },
}


}

)
a_1_0_2_28_1_2_open_dialog=function(obj){
  let data=obj.data;
  let callback=obj.callback;
  if(!window.a_1_0_2_28_1_2_dialog_dom){

      new_dom = document.createElement('a_1_0_2_28_1_2_dialog');  
      new_dom.id = 'a_1_0_2_28_1_2_dialog'; // 为div设置一个唯一的ID 
      document.body.appendChild(new_dom);
      //设置dom属性 ref值为ref_obj
      new_dom.setAttribute('ref', 'ref_obj');
      let t_deepcopy_data=JSON.parse(JSON.stringify({}));
      new_dom.setAttribute(':deepcopy_data',"deepcopy_data");//初始化vue模板的参数
      let vue_dct={'el':new_dom,data:{true:true,false:false,null:null,deepcopy_data:t_deepcopy_data}}
      let new_vue=new Vue(vue_dct);
      // window.test_vue=new_vue;
      window.a_1_0_2_28_1_2_dialog_dom=new_vue.$el;
      // next_dom2=new_vue.$el;
      window.a_1_0_2_28_1_2_dialog_vue=new_vue.$refs.ref_obj;
  }
  window.a_1_0_2_28_1_2_dialog_vue.dialogVisible=true;
  window.a_1_0_2_28_1_2_dialog_vue.初始化(data);
  window.a_1_0_2_28_1_2_dialog_vue.callback=callback;
}

Vue.component2('a_1_0_2_28_1', {  
    template: `
        <div  :class="{ 'a_1_0_2_28_1_lines test': data.true, 'a_1_0_2_28_1_lines_onclick': data.onclick_flag }" @click="handle_click" v-show="show_flag">
        <span :style="'padding-left: '+data._space_+'px;'"></span>
        <span  v-if="data.icon1_show_flag":class="{'icon iconfont':data.true,'icon-right':data.close,'icon-down':data.close==false}"></span>
        
        <span  class="a_1_0_2_28_1_hid_line" style="color:#bcbcbc">{{data.name}}</span>
        <div style="display:inline-block;flex:1;">
        <div style="display:flex;
    justify-content: flex-end;
    display: flex;">
    
        <div  @click="click1($event,k)" v-for="(v,k) in data.icon_data"
        :key="k">
         <a_1_0_3_0_0 style="display: inline-block;"
         :deepcopy_data="v"></a_1_0_3_0_0>
        </div>
        </div>
        </div>

        </div>
`,
data(){
    return{
        show_flag:true,
        data:{
            onclick_flag:false,
            tree_data:{},//
            icon_data:{},
            icon1_show_flag:true,
            click:null,
            click_obj:null,
            true:true,
            false:false,
            close:true,
            name:"",
            _space_:0,






        },
        
        dialogVisible: false,
        form: {
          index:1,
          en_name: '',
          field_type: '',
          default_value: '',
          ch_name: '',
          note: '',
          ps:{
"params1":""
}
        }
    }
},
methods:{
    init_val:function(){
      this.data.ps={};
    },
    handle_click:async function(event){
        //点击当前 高亮显示
        try{//console.log("高亮",this.data.path);
this.data.tree_data.set_onclick_flag(this.data.path)}catch{}
        // /* console.log("我点击了一次")*/
        try{
            if(!this.data.tree_data.check_dct[this.data.path]){
                await this.data.刷新目录1();
            }
            /*console.log("?2")*/}
        catch{}

        if (this.data.click){
            try{
                this.data.click(event)
            
                // console.log("start click2")
            }
            catch{}
            return 
        }


        if (this.data.click_obj){
            try{
                lhp_run_func(this.data.click_obj.func,this.data.click_obj.args)
            
                // console.log("start click3")
            }
            catch{}
            return 
        }
        try{
            this.data.click_handle(this.data.path,this.data.close);
        }catch{}
    },
    click1:async function(event,k){
       /* console.log(',,,',this.data.icon_data[k].click)*/
        lhp_run_func(this.data.icon_data[k].click);
        if(!this.data.click_stop){event.stopPropagation();}//阻止父级

    }
},

mounted:function(){
    /*console.log("210的deepcopydata",_this.deepcopy_data)*/
let urls=_this.deepcopy_data.tree_data.url;
let tree_data=_this.deepcopy_data.tree_data;
_this.data.全局配置对象=tree_data['全局配置对象'];
_this.data.add_new=function(field_data){
  let base_info={
    deepcopy_data:JSON.parse(JSON.stringify(field_data)),
    vue_name:'a_1_0_2_29_1',
    index:0,
  }
  base_info['deepcopy_data']['name']=field_data['en_name']+`[${field_data['ch_name']}]`;
  
    try{
        if(!_this.data.db_id){
            let path_l=_this.data.path.split(".");
            _this.data.db_id=path_l[path_l.length-1];
        }
    }
    catch{}
//更新数据 

//更新数据 
let update_val={
    "type":"change_data",
    "data_type":"set_list",//类型 修改数据
    update_params:[
      {//将路径为path的数据 进行 +1操作 并且存入属性add中 提供给data里面携带@add的属性调用
        name:'@index',
        path:`db_config.dict.1.dict.${_this.data.db_id}.base_info.index`,//数据路径
        use:'++s'
      },
    ],
    "postput":[{
        'path':`db_config.dict.1.dict.${_this.data.db_id}.dict.@index`,
        'data':{base_info:base_info,dict:{}}//字段数据
      },
      {
        'path':`db_config.dict.1.dict.${_this.data.db_id}.base_info`,
        'data':{
            "index":"@index",
        }
      },
    
    ],
  }
//向服务端websocket发送消息
_this.data.全局配置对象.更新(update_val);
}

_this.data.change_data=function(data){
  try{
      if(!_this.data.db_id){
          let path_l=_this.data.path.split(".");
          _this.data.db_id=path_l[path_l.length-1];
      }
  }
  catch{}
  //更新数据 
let deepcopy_dat=JSON.parse(JSON.stringify(data));
deepcopy_dat['name']=data['en_name']+`[${data['ch_name']}]`;
  data['deepcopy_data']={"name":data['ch_name']}
  //更新数据 
  let update_val={
      "type":"change_data",
      "data_type":"set_list",//类型 修改数据
      "delete":[{
        "path":`db_config.dict.1.dict.${_this.data.db_id}.base_info.deepcopy_data.ps`
      }],
      "postput":[{
          'path':`db_config.dict.1.dict.${_this.data.db_id}.base_info.deepcopy_data`,
          'data':deepcopy_dat,
        },
      ],
    }
  //向服务端websocket发送消息
  _this.data.全局配置对象.更新(update_val);
}
function getQueryParams() {  
  const queryParams = {};  
  const urlParams = new URLSearchParams(window.location.search);  
  for (const [key, value] of urlParams.entries()) {  
      queryParams[key] = value;  
  }  
  return queryParams;  
}  








_this.data.复制建表结构_request=request______({method:'post',url:urls.复制建表结构_url});

_this.data.复制建表结构_recv=function(received_data){
    console.log("接收数据",received_data);
    if(received_data.type=='okk'){

      copy_text(received_data.message); 
      Vue.prototype.$notify({type: 'success',message: '已拷贝表'+_this.data.db_id})
    }
    复制建表结构_flag=true;
}
_this.data.复制建表结构=async function(){
  try{
      if(!_this.data.db_id){
          let path_l=_this.data.path.split(".");
          _this.data.db_id=path_l[path_l.length-1];
        _this.down_load_info=getQueryParams();
        _this.down_load_info.db_id=_this.data.db_id

      }
  }
  catch{}
    let count=0;
    _this.data.复制建表结构_flag=false;
    _this.data.复制建表结构_request({
        body_data:_this.down_load_info,
        execute_lst:[
                      {
                        'type':'func',
                        'func':_this.data.复制建表结构_recv,
                        'args':['received_data'],
                      },
                    ]
    });
    await time_sleep(20);
    while(1){
        count++;
        await time_sleep(1);
        if(_this.data.复制建表结构_flag==true){break}
        if(count>500){Vue.prototype.$notify({type: 'error',message: '复制建表结构失败'});break}
    }
}



_this.data.icon_data={
  98:{
      icon_class:"icon iconfont icon-fuzhi",
      hovertext:"fuzhi建表sql",
      add_show:false,
      click:async function(){
        _this.data.复制建表结构();



      },
    },
  99:{
      icon_class:"icon iconfont icon-write",
      hovertext:"修改属性",
      add_show:false,
      click:async function(){
        a_1_0_2_28_1_2_open_dialog({"data":_this.data,"callback":_this.data.change_data});
      },
    },
    100:{
        icon_class:"icon iconfont icon-ziduan",
        hovertext:"添加新字段",
        click:async function(){
          a_1_0_2_28_1_open_dialog({"callback":_this.data.add_new});
        }
        },
}


}

})